<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:c="http://java.sun.com/jsp/jstl/core"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.prime.com.tr/ui"
                template="./../template/WorkspaceTemplate.xhtml">

    <ui:define name="top">
        
    </ui:define>

    <ui:define name="left">
    </ui:define>

    <ui:define name="right">
   
    </ui:define>

    <ui:define name="content">

        <h2>Manage Product Base Price</h2>

        <h:form id="form">  
            <p:growl id="growl" showDetail="true" life="5000" /> 

            <p:dataTable id ="productPrices" var="product" value="#{ppManagerBean.viewAllProductPrices()}" style="border: black" 
                       
                         selection="#{ppManagerBean.selectedProduct}" selectionMode="single" emptyMessage="No products found with given criteria" >  

                <f:facet name="header">  
                    Click on "Update"  after selecting a row to update base price 
                </f:facet>  

                <!--
                <f:facet name="header2">  
                    <p:outputPanel>  
                        <h:outputText value="Search all fields:" />  
                        <p:inputText id="globalFilter" onkeyup="productsTable.filter()" style="width:150px" />  
                    </p:outputPanel>  
                </f:facet>  
                -->

                <p:column filterBy="#{product.productType}"   
                          headerText="Product Type" 
                          filterOptions="#{ppManagerBean.createFilterOptions()}" 
                          filterMatchMode="exact">  
                    <h:outputText value="#{product.productType}" />  
                </p:column>  


                <p:column   headerText="Base Price"  >  
                    <h:outputText value="#{product.basePrice}"  > 
                        <f:convertNumber maxFractionDigits="2" minFractionDigits="2"/>
                        </h:outputText>
                </p:column>  

                

                <f:facet name="footer">  
                    <p:commandButton value="Update" image="ui-icon ui-icon-pencil"  
                                     update=":dialogForm:display" oncomplete="updateDlg.show()"/>  
                    <!--
                     <p:commandButton value="Delete" image ="ui-icon ui-icon-close" update="form" oncomplete="confirmation.show()"/>
                    -->
                </f:facet>
            </p:dataTable>  




            <!--
                <p:dialog header="Update Markup" widgetVar="dlg" resizable="false">  
                <h:form id="dlgForm">  
    
                    <h:panelGrid columns="2" style="margin-bottom:10px"> 
    
                        <h:outputLabel for="productType" value="Product Type:" />  
                        <h:outputText value="{product.productType}" /> 
    
                        <h:outputLabel for="wsMarkup" value="Whole Sales Markup:" />  
                        <p:inputText id="wsMarkup" value="{product.wsMarkup}" />  
    
                        <h:outputLabel for="dsMarkup" value="Direct Sales Markup:" />  
                        <p:inputText id="dsMarkup" value="{product.dsMarkup}" /> 
    
                    </h:panelGrid>  
    
                    <p:commandButton value="Submit" action="{ppManagerBean.updateProductPrice(product.id)}" update="productPrices,display" oncomplete="dlg.hide();"/>  
    
                </h:form>  
            </p:dialog>
            -->

        </h:form> 



        <p:dialog id="updateDialogue" header="Update Base Price" widgetVar="updateDlg" resizable="false"  
                  width="400" showEffect="clip" hideEffect="fold">  

            <h:form id="dialogForm">

                <h:panelGrid id="display" columns="2" cellpadding="4">  

                    <h:outputText value="Product Type:" />
                    <h:outputText value="#{ppManagerBean.selectedProduct.productType}" />  


                    <h:outputText value="Base Price:" />   
                    <p:inputText id="basePrice" required="true" requiredMessage="Base Price is required."
                                 value="#{ppManagerBean.selectedProduct.basePrice}" />

                </h:panelGrid>  
                <p:commandButton value="Submit" actionListener="#{ppManagerBean.updateBasePrice}" update="form" oncomplete="handleLoginRequest(xhr, status, args)"/>  

            </h:form>  
        </p:dialog>

        <script type="text/javascript">  
            function handleLoginRequest(xhr, status, args) {  
                 if(args.validationFailed || !args.valid) {  
                 jQuery('#updateDialogue').parent().effect("shake", { times:3 }, 100);  
                 } else {  
                     updateDlg.hide();  
                    //jQuery('#updateDlg').fadeOut();  
                }  
            }  
        </script>  
        <!--
        <p:confirmDialog message="Are you sure?" width="200"  
                         showEffect="explode" hideEffect="explode"  
                         header="Confirm" severity="alert" widgetVar="confirmation">  
            <h:form>
            <p:commandButton value="Yes" update="form" actionListener="{ppManagerBean.deleteProductPrice}" oncomplete="confirmation.hide()"/>  
            <p:commandButton value="Cancel" onclick="confirmation.hide()" type="button" />  
            </h:form>
        </p:confirmDialog> 
        -->

    </ui:define>

    <ui:define name="bottom">
       
    </ui:define>

</ui:composition>
